package com.lehecai.core.api.openapi;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.util.CoreDateUtils;

public class OpenAPIAppRecommendDownload extends AbstractApiResultBean {
	
	public static final String QUERY_APP_ID = "app_id";
	public static final String QUERY_APP_NAME = "app_name";
	public static final String QUERY_APP_TYPE_RECOMMEND = "app_type";
	public static final String QUERY_SIGN = "sign";
	public static final String QUERY_APP_BEGIN_DATE = "start";
	public static final String QUERY_APP_END_DATE = "end";
	public static final String QUERY_APP_IOS_NUM = "ios";
	public static final String QUERY_APP_ANDROID_NUM = "android";
	
	public static final String QUERY_APP_DOWN_DATE = "app_down_date";

	
	private long appId;					            //应用编号
	private String appName;				            //应用名称
	private OpenAPIAppRecommendType appType;        //应用类型（1=ios应用， 2=android应用）
	private Date appDownDate;				        //应用添加时间
	private Integer iosNum;				            //ios下载次数
	private Integer androidNum;				        //andriodNum下载次数
	
	public static OpenAPIAppRecommendDownload convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		OpenAPIAppRecommendDownload openAPIAppRecommendDownload = new OpenAPIAppRecommendDownload();
		openAPIAppRecommendDownload.setAppId(getLong(object, QUERY_APP_ID));
		openAPIAppRecommendDownload.setAppName(getString(object, QUERY_APP_NAME));
		openAPIAppRecommendDownload.setAppType(OpenAPIAppRecommendType.getItem(getInt(object, QUERY_APP_TYPE_RECOMMEND)));
		openAPIAppRecommendDownload.setAppDownDate(CoreDateUtils.parseDate(getString(object, QUERY_APP_DOWN_DATE), CoreDateUtils.DATE));
		openAPIAppRecommendDownload.setIosNum(Integer.valueOf(getString(object, QUERY_APP_IOS_NUM)));
		openAPIAppRecommendDownload.setAndroidNum(Integer.valueOf(getString(object, QUERY_APP_ANDROID_NUM)));
		return openAPIAppRecommendDownload;
	}
	
	public static List<OpenAPIAppRecommendDownload> convertFromJSONArray(JSONArray array) {
		if (array == null) {
			return null;
		}
		List<OpenAPIAppRecommendDownload> list = new ArrayList<OpenAPIAppRecommendDownload>();
		for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}
	
	public long getAppId() {
		return appId;
	}
	public void setAppId(long appId) {
		this.appId = appId;
	}
	public String getAppName() {
		return appName;
	}
	public void setAppName(String appName) {
		this.appName = appName;
	}

	public OpenAPIAppRecommendType getAppType() {
		return appType;
	}

	public void setAppType(OpenAPIAppRecommendType appType) {
		this.appType = appType;
	}


	public void setAppDownDate(Date appDownDate) {
		this.appDownDate = appDownDate;
	}

	public Date getAppDownDate() {
		return appDownDate;
	}

	public void setIosNum(Integer iosNum) {
		this.iosNum = iosNum;
	}

	public Integer getIosNum() {
		return iosNum;
	}

	public void setAndroidNum(Integer androidNum) {
		this.androidNum = androidNum;
	}

	public Integer getAndroidNum() {
		return androidNum;
	}

}
